#ifndef HEXVIEW_H
#define HEXVIEW_H

#include <QWidget>
#include <QFile>
#include <QModelIndex>

class QHexEdit;
class QSplitter;
class QListView;
class QTableView;

class DataView : public QWidget
{
    Q_OBJECT
public:
    enum ViewMode {
        Hex,
        Fixed,
        Frame,
        UDF,
        PDXP,
    };

    QAction* deleteAction;
    QAction* deleteColumnAction;
    QAction* deleteRowAction;
    QAction* saveAsAction;
    QAction* filterAction;
    QAction* filterColumnAction;

    explicit DataView(QWidget *parent = 0);
    DataView(QString file, QWidget *parent = 0, bool temp = false);
    bool openFile(QString name);
    const QFile& getFile(void);
    qint64 cursorPosition(void);
    QByteArray dataAt(qint64 pos, qint64 count = -1);
    void indexOf(const QByteArray &ba, qint64 from);
    void lastIndexOf(const QByteArray &ba, qint64 from);
    void toggleHexView(void);
    void toggleFixedView(void);
    void toggleUDFView(void);
    void togglePDXPView(void);
    void toggleFrameView(void);
    void createRecordView();
    void adjust(ViewMode mode);
    ViewMode getViewMode(void) { return viewMode; }
    void HexEditSettingchaged(void);
    bool HexEditisModified();
    bool IstempFile();

signals:
    void viewAddressChanged(DataView*, qint64);
    void openTempFile(const QString fileName);

public slots:
    void savaAs(void);
    void redo(void);
    void undo(void);
    void deletetempFile();

protected:

private:
    QSplitter* vSplitter;
    QHexEdit* hexEdit;
    QTableView* recordView;
    QFile file;
    ViewMode viewMode;
    bool tempFile;

    void init(void);
    void createActions(void);
    QString getSaveFileName(void);
    void deleteRows(const QModelIndexList& rows);
    void deleteColumns(const QModelIndexList& cols);

private slots:
    void addressChanged(qint64 address);
    void recordClicked(const QModelIndex& index);
    void columnsInserted(const QModelIndex &parent, int first, int last);
    void rowsInserted(const QModelIndex &parent, int first, int last);
    void tableDeleted(void);
    void tableSaveAs(void);
    void tableFilter(void);
    void columnFilter(void);
    void horizontalHeaderMenuRequested(const QPoint& pos);
    void verticalHeaderMenuRequested(const QPoint& pos);
    void tableContextMenuRequested(const QPoint& pos);
    void deleteRow(void);
    void deleteColumn(void);

    // QObject interface
public:
    bool eventFilter(QObject *watched, QEvent *event);
};

#endif // HEXVIEW_H
